using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace EventAbstractionAPI.RuleTableCtrl
{
    public partial class Options : Form
    {
        private ArrayList parameterList = new ArrayList();

        public Options(String XPathExpression)
        {
            InitializeComponent();
            xpathExpression = XPathExpression;
        }

        public String xpathExpression
        {
            get { return textBox1.Text; }
            set { textBox1.Text = value; }
        }

        private void textBox_KeyUp(object sender, KeyEventArgs e)
        {
            //any of the property textboxes have been updated. 
            //Lets try to update the xpath expression.

            //((TextBox)sender)

            parameterList.Clear();
            String xpath_output = "//*";

            if (textBox2.Text != "") { parameterList.Add(new myTuple("name",textBox2.Text)); }
            if (textBox3.Text != "") { parameterList.Add(new myTuple("tag", textBox3.Text)); }
            if (textBox4.Text != "") { parameterList.Add(new myTuple("type", textBox4.Text)); }
            if (textBox5.Text != "") { parameterList.Add(new myTuple("regularexpression", textBox5.Text)); }
            if (textBox6.Text != "") { parameterList.Add(new myTuple(textBox6.Text, textBox7.Text)); }
            

            int i = 1;
            foreach (myTuple t in parameterList)
            {
                if (i == 1 && i < parameterList.Count)
                {
                    xpath_output += "[" + t.theProperty + "='" + t.theValue + "' & ";
                }
                else if (i == 1)
                {
                    xpath_output += "[" + t.theProperty + "='" + t.theValue + "']";
                }
                else if (i < parameterList.Count)
                {
                    xpath_output += "" + t.theProperty + "='" + t.theValue + "' & ";
                }
                else
                {
                    xpath_output += "" + t.theProperty + "='" + t.theValue + "']";
                }
                i++;
            }

            textBox1.Text = "xpath:" + xpath_output;
        }

        private class myTuple
        {
            private String str_value = "";
            private String str_property = "";

            public myTuple(String theproperty, String thevalue)
            {
                str_value = thevalue;
                str_property = theproperty;
            }

            public String theValue
            {
                get { return str_value; }
                set { str_value = value; }
            }

            public String theProperty
            {
                get { return str_property; }
                set { str_property = value; }
            }
        }
    }
}